<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>用户编辑</title>
<block th:replace="commonBase"></block>   
</head>
<link th:href="@{/hplus/css/plugins/layui/css/layui.css?v=4.1.0}" rel="stylesheet" />  
<script th:src="@{/hplus/js/jquery.min.js?v=2.1.4}"></script>     
<script th:src="@{/hplus/css/plugins/layui/layui.js}"></script>  
<body>
<div class="mini-fit">
	<form id="form1" method="post">
	    <div style="display:none"> 
			<input class="mini-hidden" name="oldId" id="oldId"/>
        </div>     
		<div style="padding-left:25px;padding-bottom:5px;">
			<table style="margin-top: 8px;border-collapse:separate; border-spacing:0px 5px;">
				<tr>
					<td align="right" width="70px">公路等级：</td>     
					<td>    
					   <input id="roadType" name="roadType" required="true"  class="mini-combobox" style="width: 150px;" valueField="roadTypeCode" textField="roadTypeName" allowInput="false" showNullItem="false"  onvaluechanged="roadTypeChange()" /><span><font color="red">*</font></span>
					</td>
					<td align="right" width="100px">编号：</td>         
					<td>
					   <input name="id" id="id" class="mini-textbox" style="width:150px;" required="true"  requiredErrorText="不可为空" emptyText="编号" onblur="checkIdExist()"/><span><font color="red">*</font></span><span><font color="red" id="tipMessage"></font></span>
					</td>         
				</tr>
				<tr>
					<td align="right">父编号：</td>
					<td>    
					   <input class="mini-treeselect" style="width: 150px;" textField="id" valueField="id"  parentfield="pid" name="pid" id="tree1" emptyText="父编码"  required="true"  requiredErrorText="不可为空"/><span><font color="red">*</font></span>
					</td>                   
					<td align="right">分值：</td>      
					<td>
					    <input name="inScores" id="inScores" class="mini-textbox" style="width:150px;" required="true"  requiredErrorText="不可为空" emptyText="分值" /><span><font color="red">*</font></span>
					</td>  
				</tr>
				<tr>
					<td align="right">项目描述：</td>
					<td>   
					    <input name="projectPrefs" id="projectPrefs" class="mini-textbox" style="width:150px;" emptyText="项目描述" />  
					</td>  
				</tr>   
			</table>
			
			<table style="margin-top: 8px;border-collapse:separate; border-spacing:0px 5px;">
				<tr>
				   <td>检查内容：</td>  
				</tr>
				<tr>
				   <td align="right">
				      <textarea class="layui-textarea" id="checkContent" name="checkContent" style="display: none;"></textarea>     
				   </td>
				</tr>
				<tr>
				   <td>检查标准：</td>  
				</tr>
				<tr>
				   <td align="right">
				      <textarea class="layui-textarea" id="checkStand" name="checkStand" style="display: none;"></textarea>     
				   </td>
				</tr>
				<tr>
				   <td>评分要点：</td>  
				</tr>
				<tr>
				   <td align="right">
				      <textarea class="layui-textarea" id="checkMain" name="checkMain" style="display: none;"></textarea>     
				   </td>
				</tr>
			</table>
		</div>
	</form>
	</div>
	<div class="mini-toolbar" style="text-align:center;height:40px;padding-top:10px;padding-bottom:8px;" 
        borderStyle="border-left:0;border-bottom:0;border-right:0;">
        <a class="mini-button" onclick="onOk" plain="true" iconCls="fa fa-save" style="width:85px;margin-right:20px;">保存</a>
        <span style="display:inline-block;width:25px;"></span>
        <a class="mini-button" onclick="onCancel" plain="true" iconCls="fa fa-close" style="width:85px;">关闭</a>
    </div>
</body>
<script type="text/javascript">
 /*<![CDATA[*/
    
   mini.parse();
   var action = "new";
   var form = null;
   var tree = null;//树对象
   var indexCheckContent = null;
   var indexCheckStand = null;
   var indexCheckMain = null;
   var layedit = null;
   var checkFlag = false;
   layui.use('layedit', function(){
	  var $ = layui.jquery;   
	  layedit = layui.layedit;
	  
	  //构建一个默认的编辑器
	  indexCheckContent = layedit.build('checkContent', {
		  height: 70 //设置编辑器高度  
	  });    
	  
	  indexCheckStand = layedit.build('checkStand', {
		  height: 70 //设置编辑器高度  
	  }); 
	  
	  indexCheckMain = layedit.build('checkMain', {
		  height: 70 //设置编辑器高度     
	  });      
   }); 

   function setData(data) {
		action = data.action;//获取指令，是新增 还是修改
		form = new mini.Form("#form1");//获取表单对象
		data = mini.clone(data);//获取克隆数据
		var roadTypeData = [{"roadTypeCode":"H","roadTypeName":"高速公路"},{"roadTypeCode":"P","roadTypeName":"普通公路"}];  
		mini.get("roadType").setData(roadTypeData); 
		tree = mini.get("tree1");
	    if (action == "edit") {
	    	loadPid(data.roadType);       
	        $("#checkContent").text(data.oneData.checkContent);
 	        $("#checkStand").text(data.oneData.checkStand);
 	        $("#checkMain").text(data.oneData.checkMain);        
 	        mini.get("id").setValue(data.oneData.id); 
 	        mini.get("tree1").setValue(data.oneData.pid); 
 	        mini.get("inScores").setValue(data.oneData.inScores); 
 	        mini.get("projectPrefs").setValue(data.oneData.projectPrefs); 
 	        mini.get("roadType").setValue(data.roadType);       
 	        mini.get("oldId").setValue(data.oneData.id);
 	        form.setChanged(false);   
 	        checkFlag = true; 
 	        mini.get("roadType").setEnabled(false);         
	    }else{
	    	mini.get("roadType").select(0); 
	    	loadPid("H");
	    	data = mini.clone(data);
	    }
	}   
	
	function roadTypeChange(){
		var roadType = mini.get("roadType").getValue(); 
		loadPid(roadType);   
		checkIdExist(); //校验编号是否重复
	}
	
	function checkIdExist(){   
		var id =  mini.get("id").getValue().trim();
		if(null == id || id.length == 0){  
			$("#tipMessage").text("");          
			return;
		}
		if("0" == id){
			$("#tipMessage").text("编码重复");   
			return;
		}
		if(action=="new"){        //新增
			 ajaxCheckIsExist(id);   
		}else{                    //编辑
			 var oldId = mini.get("oldId").getValue(); 
			 if(id != oldId ){
				 ajaxCheckIsExist(id);   
			 }else{
				 checkFlag = true;
				 $("#tipMessage").text(""); 
			 }
		}
	}
	
	function ajaxCheckIsExist(id){
		var roadType = mini.get("roadType").getValue(); 
		$.ajax({
	        url: basePath+"scoringCriteria/checkIdExist",
			type: 'post',
	        data: {"roadType":roadType,"id":id},
	        success: function (successData) {
	        	 var message = mini.decode(successData);
    			 if(message.type=='200'){
    				 $("#tipMessage").text("");     
    				 checkFlag = true;
    			 }else{
    				 $("#tipMessage").text(message.msg);
    				 checkFlag = false;    
    			 }  
	        },
	        error: function (XMLHttpRequest, textStatus, errorThrown) {
	        	$("#tipMessage").text("校验错误");
	        }  
	    });  
	}
	
	//初始化父编号
	function loadPid(roadType){   
		tree.setUrl(basePath+"scoringCriteria/getPidTreeByRoadType?roadType="+roadType);
	}
	
	//新增xx
	function dataAdd(json){
		$.ajax({
	        url: basePath+"scoringCriteria/dataAdd",
			type: 'post',
	        data: {data:json},
	        cache: false,
	        success: function (successData) {
	        	var message = mini.decode(successData);
	        	var msg = message.msg;//获取组织xxID，用于树节点定位
	        	mini.unmask(document.body);
	        	if(message.type == '200'){
	            	showMsg("评分标准添加成功","success",800,"center","center",closeWindow(msg));
	        	}else{
	        		showMsg("评分标准添加失败","warning",800,"center","center");
	        	}
	        },
	        error: function (XMLHttpRequest, textStatus, errorThrown) {
	        	 mini.unmask(document.body);
	        	 showMsg("评分标准添加错误","danger",800,"center","center");
	        }
	    });
	}
	
	//更新xx信息
	function dataUpdate(json){
		$.ajax({
	        url: basePath+"scoringCriteria/dataUpdate",
			type: 'post',
	        data: { data: json},
	        cache: false,
	        success: function (successData) {
	        	var message = mini.decode(successData);
	        	var msg = message.msg;//获取组织xxID，用于树节点定位
	        	mini.unmask(document.body);
	        	if(message.type == '200'){
        			showMsg("评分标准更新成功","success",800,"center","center",closeWindow(msg));
	        	}else{
	        		showMsg("评分标准更新失败","warning",800,"center","center");
	        	}
	        },
	        error: function (jqXHR, textStatus, errorThrown) {
	        	mini.unmask(document.body);
	            showMsg("评分标准更新错误","danger",800,"center","center",closeWindow);
	        }
	    });
	}

	function saveData() {
	    var o = form.getData(); 
	    form.validate();
	    if (form.isValid() == false) {
	    	mini.alert("请完善信息...","温馨提示");    
	    	return;
	    }
        if(!checkFlag){
      	    mini.alert("编码已经存在，请重新输入","温馨提示");      
      	    return;
        }  
	    o.checkContent = layedit.getContent(indexCheckContent);
	    o.checkStand = layedit.getContent(indexCheckStand);
	    o.checkMain = layedit.getContent(indexCheckMain);
	    var json = mini.encode(o);       
	    mini.mask({
	        el: document.body,
	        cls: 'mini-mask-loading',
	        html: '加载中...'
	    });    
	    if (action == "edit"){
	        dataUpdate(json);
	    }else{
	    	dataAdd(json);
	    }
	}
	
	
	function onOk(){
		saveData();
	}
	
	function closeWindow(action) {
	    if (action == "close" && form.isChanged()) {
	        if (confirm("数据被修改了，是否先保存？")) {
	            return false;
	        }
	    }
	    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
	    else window.close();            
	}
	
	function onCancel(){
		closeWindow("close");
	}
/*]]>*/
</script>
</html>